<template>
  <div id="AgentExpandHistory">
    <div id="homeBar">
      <mu-appbar title="推广记录" style="background-color:#409EFF">
        <mu-icon-button  icon="arrow_back_ios" slot="left" :to="{name: 'Home' }"/>
        <span v-if="this.isCarrieroperator"  class="totalExpand" slot="left">总{{this.totalExpand}}</span>
      </mu-appbar>
    </div>

    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="todayNdot"
        label="推广业绩">
      </el-table-column>
      <el-table-column
        prop="settleDate"
        label="日期">
      </el-table-column>
    </el-table>

    <el-row>
      <center>
        <el-pagination
          small
          layout="prev, pager, next"
          :total="condition.total"
          :page-size="condition.pageSize"
          :current-page="condition.currentPage"
          @current-change="handleCurrentChange">
        </el-pagination>
      </center>
    </el-row>
  </div>
</template>

<style>
  #AgentExpandHistory .totalExpand {
    margin-left: 4px;
  }
  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
</style>

<script>
  import moment from 'moment'
  export default {
    methods: {
      init () {
        this.getExpandHistory()
        if (this.isCarrieroperator) {
          this.getTotalExpand()
        }
      },
      handleCurrentChange (val) {
        this.condition.currentPage = val
        this.getExpandHistory()
      },
      getExpandHistory () {
        let that = this
        this.$axios({
          method: 'get',
          url: '/api/AgentService.getExpandHistory',
          params: this.condition
        })
        .then(function (resp) {
          if (resp.data.status === 'success') {
            for (let item in resp.data.data) {
              resp.data.data[item].settleDate = moment(resp.data.data[item].settleDate).format('YYYY-MM-DD')
            }
            that.tableData = resp.data.data
            that.condition.total = resp.data.page.total
          }
        })
      },
      getTotalExpand () {
        let that = this
        this.$axios({
          method: 'get',
          url: '/api/AgentService.getTotalExpand'
        })
        .then(function (resp) {
          if (resp.data.status === 'success') {
            that.totalExpand = resp.data.data
          }
        })
      }
    },
    data () {
      return {
        tableData: [],
        condition: {
          currentPage: 1,
          pageSize: 10,
          total: 0,
          account: sessionStorage.getItem('account')
        },
        totalExpand: 0,
        isCarrieroperator: false
      }
    },
    mounted () {
      if (sessionStorage.getItem('role') === 'carrieroperator') {
        this.isCarrieroperator = true
      }
      this.init()
    }
  }
</script>
